// rs_anwser/pages/subject/subject.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageIndex: 1,
    collectPrompt: true,
    animation: {},
    current: 0,
    pageSize: 10,
    wrongCount: 0,
    rightCount: 0,
    total: 160,
    subjectList: [
    ],
    param: { subjectType: 'judge', userId: app.getUserId() }

  },



  changeSubject: function (e) {

    this.setData({ current: e.detail.current });
    if (e.detail.current == this.data.subjectList.length - 1) {
      app.getData(this, "entry/wxapp/getWrongList", { subjectType: 'mutilple', userId: app.getUserId() });

    }

  },
  updateCurrent: function (data) {
    this.setData({ current: data.detail });
  },
  updateSubjectList: function (data) {
    this.setData({ subjectList: data.detail });

  },
  updatePageIndex: function (data) {
    this.setData({ pageIndex: data.detail });
  },

  /**
   * 选择题目选项
   */
  selectOption: function (e) {
    var subject = this.getCurrentSubject();
    if (typeof (subject.result) == 'undefined') {
      //如果还没有没有答题
      var answer = subject.answer;
      var value = e.currentTarget.dataset.value;

      if (value == 1 && '正确' == answer) {
        subject.rightClass = 'result-right';
        this.setData({ rightCount: ++this.data.rightCount });
        subject.result = 1;
      } else {
        subject.wrongClass = 'result-wrong';
        this.setData({ wrongCount: ++this.data.wrongCount });
        subject.result = 2;
      }
      this.updateCurrentSubject(subject);
    }
    


  },

  /**
   * 
   */
  collect: function () {

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    app.getData(this, "entry/wxapp/getWrongList", { subjectType: 'judge', userId: app.getUserId() });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {


  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.selectComponent('#collect_promt').startPrompt();

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },


  /**
   * 获取题目
   */
  getCurrentSubject: function () {

    var subjectList = this.data.subjectList;
    var current = this.data.current;
    return subjectList[current];

  },

  /**
   * 更新当前题目状态
   */
  updateCurrentSubject: function (subject) {
    var subjectList = this.data.subjectList;
    var current = this.data.current;
    subjectList[current] = subject;
    this.setData({ subjectList: subjectList });
  }
})